package com.whalewire.web.rest;

import java.util.Date;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import org.springframework.stereotype.Service;

import com.whalewire.domain.LogEntry;
import com.whalewire.domain.LogLevel;

@Service("logService")
@Path("/logs")
public class LogService {

    @GET
    @Produces("text/plain")
	public String getDummy() {
		return "HALLI HALLI HALLO";
	}

    @POST
    @Consumes("text/plain")
    @Path("/info")
    public void addInfoLogEntry(String text) {
    	
    	this.addLogEntry(LogLevel.INFO, text);
    	

    }
    
    @POST
    @Consumes("text/plain")
    @Path("/error")
    public void addErrorLogEntry(String text) {
    	
    	this.addLogEntry(LogLevel.ERROR, text);

    }
    
    private void addLogEntry(LogLevel level, String text) {
    	
    	LogEntry logEntry = new LogEntry();
    	logEntry.setLogTime(new Date());
    	logEntry.setLogLevel(level);
    	logEntry.setLogText(text);
    	
    	logEntry.persist();
    	
    }
    
}


